package com.github.thinwonton.activemq.showcase.cluster.bootstrap;

import com.github.thinwonton.activemq.showcase.cluster.mq.Producer;
import com.github.thinwonton.activemq.showcase.cluster.entity.Email;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class ProducerBootstrap {

    private static final Logger logger = LoggerFactory.getLogger(ProducerBootstrap.class);

    public static void main(String[] args) throws InterruptedException {

        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
                "classpath:spring/applicationContext-producer.xml");
        context.start();

        Producer producer = context.getBean(Producer.class);

        int num = 10000000;
        for (int i = 0; i < num; i++) {
            logger.info("==>生产者:send message:" + i);
            // 邮件发送
            Email mail = new Email();
            mail.setSn("[序列号:" + i + "]");
            mail.setSubject("ActiveMQ测试");
            producer.sendMessage(mail);

            Thread.sleep(500); //500毫秒发送一次
        }

        context.stop();
    }
}
